package id.co.rho.scoring.cid.client.mvc.scoringmodel;

import id.co.rho.scoring.cid.client.mvc.AppView;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.FieldSet;
import com.extjs.gxt.ui.client.widget.form.FormPanel;
import com.extjs.gxt.ui.client.widget.form.SimpleComboBox;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
import com.extjs.gxt.ui.client.widget.layout.HBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayout;
import com.extjs.gxt.ui.client.widget.layout.VBoxLayoutData;

public class ScoringModelEditUIWeb implements ScoringModelEditUI{
	private ContentPanel dataPanel;
	private TextField<String> txtName;
	private TextField<String> txtNumber;
	private TextField<String> txtRank;
	private TextField<String> txtWeight;
	private SimpleComboBox<String> cboType;
	private Button btnSave;
	private Button btnCancel;
	private FormLayout formLayout;
    private FieldSet fsInput;
	private VBoxLayoutData vbData;
	private VBoxLayout vBoxLayout;
	private FormPanel formPanel;
	private ContentPanel content;
	
	@Override
	public void initialize() {
		fsInput = new FieldSet();
		dataPanel = new ContentPanel();
		
		formLayout = new FormLayout();
        formLayout.setLabelAlign(FormPanel.LabelAlign.LEFT);
        
        fsInput = new FieldSet();
        fsInput.setHeading("Scoring Model");
        fsInput.setLayout(formLayout);
        
        vBoxLayout = new VBoxLayout(VBoxLayout.VBoxLayoutAlign.STRETCH);		
        vbData = new VBoxLayoutData();
		
		txtName = new TextField<String>();
		txtName.setFieldLabel("Name");
		txtNumber = new TextField<String>();
		txtNumber.setFieldLabel("Number");
		txtRank = new TextField<String>();
		txtRank.setFieldLabel("Rank");
		txtWeight = new TextField<String>();
		txtWeight.setFieldLabel("Weight");
		cboType = new SimpleComboBox<String>();
		cboType.setFieldLabel("Type");
		
		fsInput.add(txtName);
		fsInput.add(txtNumber);
		fsInput.add(txtRank);
		fsInput.add(txtWeight);
		fsInput.add(cboType);
		
		cboType.add("CRITERIA");
		cboType.add("QUESTION");
		cboType.add("ANSWER");
		
        formPanel = new FormPanel();
        formPanel.setHeading("Scoring Model");
        formPanel.setScrollMode(Style.Scroll.AUTO);
        formPanel.add(fsInput);
		
        LayoutContainer lcButton = new LayoutContainer();        
        lcButton.setStyleAttribute("margin-top", "10px");
        lcButton.setLayout(new HBoxLayout());
        fsInput.add(lcButton);
		btnSave = new Button();
		btnSave.setStyleAttribute("padding-left", "5px");
		btnSave.setText("Save");
		btnCancel = new Button();
		btnCancel.setStyleAttribute("padding-left", "5px");
		btnCancel.setText("Cancel");
		lcButton.add(btnSave);
		lcButton.add(btnCancel);
		dataPanel.add(formPanel,vbData);
		content= new ContentPanel();
		content.setHeaderVisible(false);
		content.add(formPanel,vbData);
		
	}

	@Override
	public void show() {
		ContentPanel centerPanel = (ContentPanel) Registry
				.get(AppView.CENTER_PANEL);
		centerPanel.removeAll();
		centerPanel.setLayout(new FitLayout());
		centerPanel.add(content);
		centerPanel.layout();
	}
	
	@Override
	public void clearText(){
		txtName.setValue("");
		txtNumber.setValue("");
		txtRank.setValue("0");
		txtWeight.setValue("0");
		fsInput.layout();
	}

	@Override
	public TextField<String> getTxtName() {
		return txtName;
	}

	@Override
	public TextField<String> getTxtNumber() {
		return txtNumber;
	}

	@Override
	public TextField<String> getTxtRank() {
		return txtRank;
	}

	@Override
	public TextField<String> getTxtWeight() {
		return txtWeight;
	}

	@Override
	public SimpleComboBox<String> getCboType() {
		return cboType;
	}

	@Override
	public Button getBtnSave() {
		return btnSave;
	}

	@Override
	public Button getBtnCancel() {
		return btnCancel;
	}
}
